package com.sunlake.spring.main.model.admin.service.impl;

import com.sunlake.spring.main.common.utils.JwtTokenUtil;
import com.sunlake.spring.main.model.admin.service.AdminService;

import com.sunlake.spring.main.common.response.R;
import com.sunlake.spring.main.model.admin.dto.UserEmailDTO;
import com.sunlake.spring.main.model.admin.vo.UserVO;
import com.sunlake.spring.main.model.auth.mapper.UsersMapper;
import com.sunlake.spring.main.model.auth.po.UsersPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private UsersMapper usersMapper;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;
    @Override
    public R<UserVO> searchUserByEmail(UserEmailDTO userEmailDTO) {
        UsersPO userPO = usersMapper.selectByEmail(userEmailDTO.getEmail());
        if(userPO==null){
            return R.error(404,"用户不存在");
        }
        Long userId = Long.valueOf(userPO.getId());
        String userRole = userPO.getRole().getCode();
        Object status = userPO.getStatus();
        // 不在查询接口返回 refreshToken，保持仅登录/注册等认证操作签发
        UserVO userVO = new UserVO(userId,userPO.getUsername(),userPO.getEmail(),null,userRole,status.toString());

        return R.ok(200,"查询成功",userVO);
    }
}
